<?php namespace App\Http\Controllers\Api\Merchant;

use App\Http\Controllers\Controller;
use App\Merchant;
use App\MerchantMedicine;
use App\MerchantMedicineImg;
use Illuminate\Http\Request;

class DataHandleController extends Controller
{
    public function setMerchantMedicineImg(Request $request){
        $key = $request->get("key");

        if($key != "action_yjk")
            return response()->json(['level' => 'error','message' => 'no_access']);

        $merchantIds = [52,69,70];
        $merchantMedicines = MerchantMedicine::whereIn('merchant_id',$merchantIds)->get();
        if(count($merchantMedicines) > 0){
            foreach ($merchantMedicines as $merchantMedicine){
                $hasMerchantMedicineImg = MerchantMedicineImg::whereMerchantMedicineId($merchantMedicine->id)->whereImgId(99078)->first();
                if(!$hasMerchantMedicineImg){
                    $newMerchantMedicineImg = new MerchantMedicineImg();
                    $newMerchantMedicineImg->merchant_medicine_id = $merchantMedicine->id;
                    $newMerchantMedicineImg->img_id = 99078;
                    $newMerchantMedicineImg->sort = 1;
//                    $newMerchantMedicineImg->created_at = "2021-01-22 20:00";
//                    $newMerchantMedicineImg->updated_at = "2021-01-22 20:00";
                    $newMerchantMedicineImg->save();
                }
            }
        }

        return response()->json(['level' => 'success','message' => 'complete']);
    }
}
